package com.grupobbva.seguridad.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.apache.log4j.Logger;

import com.grupobbva.seguridad.filter.ValidacionSessionFilter_NEW;

public class Conexion {
	
	private static final Logger log=Logger.getLogger(Conexion.class);
	
	public static Connection getConnection(String jndi) throws Exception {
		InitialContext context = null;
		DataSource dataSource = null;
		Connection con = null;
		try {
			context = new InitialContext();
			dataSource = (DataSource) context.lookup(jndi);
		    //dataSource = (DataSource) context.lookup("java:/comp/env/jdbc/ADMCON");
		    con = dataSource.getConnection();
		} catch(Exception e){
			throw e;
		}
	    return con;
	}
	
	public static void close(Connection cnn, Statement stm, ResultSet rst) {
		try {
			if (rst != null) {
				rst.close();
			}
			if (stm != null) {
				stm.close();
			}
			if (cnn != null) {
				cnn.close();
			}
		} catch (SQLException e) {
			log.error(e.getMessage(),e);
		}
	}
}
